package cn.edu.jsu.zjj.service.impl;

import cn.edu.jsu.zjj.mapper.DocuInduceMapper;
import cn.edu.jsu.zjj.model.entity.DocuInduce;
import cn.edu.jsu.zjj.service.DocuInduceService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class DocuInduceServiceImpl extends ServiceImpl<DocuInduceMapper, DocuInduce> implements DocuInduceService {

    @Autowired
    private DocuInduceMapper docuInduceMapper;

    @Override
    public Page<DocuInduce> queryDocuInduce(Page<DocuInduce> page, String name, String userMajorId) {
        LambdaQueryWrapper<DocuInduce> queryWrapper = new LambdaQueryWrapper<>();

        if (name != null && !name.isEmpty()) {
            queryWrapper.like(DocuInduce::getName, name);
        }

        if (userMajorId != null && !userMajorId.isEmpty()) {
            queryWrapper.and(wrapper -> {
                wrapper.like(DocuInduce::getMajorId, userMajorId)
                        .or().like(DocuInduce::getMajorId, userMajorId + "-");
            });
        }

        queryWrapper.eq(DocuInduce::getIsDeleted, 0);
        queryWrapper.orderByDesc(DocuInduce::getCreateTime);

        return docuInduceMapper.selectPage(page, queryWrapper);
    }
}